package com.example.administrator.yunniuusedcar.fragment.ShoppInfo_Fragment;
import android.annotation.SuppressLint;
import android.widget.ListView;

import com.example.administrator.common.base.BaseFragment;
import com.example.administrator.yunniuusedcar.R;
import com.example.administrator.yunniuusedcar.adapter.GuiGeAdapter;
import com.example.administrator.yunniuusedcar.model.mode_benn.IHttpService;
import com.example.administrator.yunniuusedcar.model.mode_benn.RanCarXiangQingBean;
import com.google.gson.Gson;
import com.squareup.picasso.Picasso;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import okhttp3.Call;

/**
 * Created by Administrator on 2017/12/8.
 *  商品信息  规格
 */

@SuppressLint("ValidFragment")
public class GuiGeInfoFragment extends BaseFragment {

    private ListView type_listview;
    private GuiGeAdapter typeAdapter;

    private int resultID;
    @SuppressLint("ValidFragment")
    public GuiGeInfoFragment(int car_id) {
        super();
        resultID = car_id;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.fragment_guige_info;
    }

    @Override
    public void initView() {
        type_listview = findView(R.id.type_listview);
        typeAdapter = new GuiGeAdapter(getContext());
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {
        String ul = IHttpService.URL2 + IHttpService.GETCARDETAIL;    // 商品 详情
        //String.valueOf(resultID)  car_id
        OkHttpUtils.post().url(ul).addParams("sign",IHttpService.SignVal).addParams("car_id", String.valueOf(resultID)).build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        RanCarXiangQingBean ranCarInfoBean = new Gson().fromJson(response, RanCarXiangQingBean.class);
                        if(ranCarInfoBean.code==1){
                            type_listview.setAdapter(typeAdapter);

                            typeAdapter.setData(ranCarInfoBean.data.spec);
                        }
                    }
                });
    }
}
